package com.yanqu.road.server.channelserver.cmd.activity.washe;

import com.yanqu.road.entity.activity.washe.data.WasheUserKey;
import com.yanqu.road.logic.pb.WashePb2;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.WasheProto;
import com.yanqu.road.server.channelserver.cmd.ChannelCommand;
import com.yanqu.road.server.channelserver.logic.ChannelMessageHelper;
import com.yanqu.road.server.channelserver.manager.activity.washe.ChannelWasheActivity;
import com.yanqu.road.server.channelserver.manager.activity.washe.ChannelWasheMgr;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.protocol.ChannelProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = ChannelProtocol.N_WASHE_GET_DAY_SCENE, desc = "")
public class ChannelWasheGetDaySceneCmd extends ChannelCommand {

    private WasheUserKey userKey;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        WasheProto.ChannelWasheGetDaySceneReqMsg reqMsg = WasheProto.ChannelWasheGetDaySceneReqMsg.parseFrom(packet.getBytes());
        userKey = WashePb2.parseWasheUserKey(reqMsg.getUserKey());
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        ChannelWasheActivity activity = ChannelWasheMgr.getActivity(userKey.getChannelId());
        if (activity == null) {
            log.error("can not find washe activity! channelId {}.", userKey.getChannelId());
            ret = -1;
            return;
        }

        ret = activity.getDaySceneByCmd(userKey);
    }

    @Override
    public void sendData() {
        if (ret != 0) {
            WasheProto.ChannelWasheSyncDaySceneRespMsg.Builder builder = WasheProto.ChannelWasheSyncDaySceneRespMsg.newBuilder();
            ChannelMessageHelper.sendGamePacket(GameProtocol.S_WASHE_SYNC_DAY_SCENE, builder, userKey.getChannelId(), userKey.getServerId(), 0);
        }
    }
}
